package com.mallcai.bigdata.ladon.dpl.mapper.system;

import com.mallcai.bigdata.ladon.dpl.entity.system.User;
import com.mallcai.bigdata.ladon.dpl.mapper.system.provider.UserSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

import static com.mallcai.bigdata.ladon.dpl.mapper.system.provider.UserSqlProvider.TB_USER;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface UserMapper {

    @InsertProvider(type = UserSqlProvider.class, method = "insert")
    public int insert(User user);

    @UpdateProvider(type = UserSqlProvider.class, method = "update")
    public int update(User user);

    @UpdateProvider(type = UserSqlProvider.class, method = "delete")
    public int delete(User user);

    @SelectProvider(type = UserSqlProvider.class, method = "getByParams")
    public List<User> getByParams(@Param("params") Map<String, Object> params);

    @Select({
            "SELECT * FROM " + TB_USER + " WHERE archive  = 0 AND  username = #{username}"
    })
    public List<User> getSameUsername(@Param("username") String username);

    @Select({
            "SELECT * FROM " + TB_USER + " WHERE archive = 0 AND  username = #{username}"
    })
    public User getByUsername(@Param("username") String username);

    @Select({
            "SELECT * FROM " + TB_USER + " where archive = 0"
    })
    public List<User> getAllByAppId();

    @SelectProvider(type = UserSqlProvider.class, method = "findDetailById")
    public User getById(@Param("id") Long id);

    @Select({
            "SELECT * FROM " + TB_USER + " WHERE archive = 0 AND email_active_code = #{emailCode}"
    })
    public User getByEmailCode(@Param("emailCode") String emailCode);

    @Update({
            "UPDATE " + TB_USER + " SET status = 1 WHERE id = #{userId}"
    })
    int activateUser(@Param("userId") Long userId);

    @SelectProvider(type = UserSqlProvider.class, method = "isExistEmail")
    int isExistEmail(@Param("email") String email, @Param("filterId") Long filterId);
}
